package org.redis.cluster.redis.transport.codec.server;

import java.nio.ByteBuffer;

import org.apache.commons.lang3.ArrayUtils;
import org.redis.cluster.transport.protocol.ProtocolEncoder;

public class RedisServerProtocolEncoder implements ProtocolEncoder {
	
	@Override
	public byte[] encode(Object value) {
		if(value==null) {
			return ArrayUtils.EMPTY_BYTE_ARRAY;
		}
		
		if(value instanceof ByteBuffer) {
			return ((ByteBuffer)value).array();
		}
		
		if(value instanceof byte[]) {
			return (byte[]) value;
		}
		
		return ArrayUtils.EMPTY_BYTE_ARRAY;
	}
}